//
//	  Stack.java
//
//	  Copyright (c) 2011 <John Lawniczak>
//	  jlawniczak340license@gmail.com
//
//    This file is part of CS102_Assignment3.
//
//    CS102_Assignment3 is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, version 3 of the License.
//
//    CS102_Assignment3 is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with CS102_Assignment3.  If not, see <http://www.gnu.org/licenses/>.
//
/**************************************************
Class Name: Stack
Author's Name: John Lawniczak
Date: 05-19-2010
Description of the class: Stores generic types in a typical stack structure
***************************************/


import java.util.EmptyStackException;


public class Stack <t>{
	private LinkedList<t> stackData;
	
	public Stack(){
		stackData = new LinkedList<t>();
	}
	
	/**************************************************
	Method Name: push
	Input to the method: t item to push to top of stack
	Output(Return value): none
	Brief description of the task: adds an element to the stack 
	Author: John Lawniczak
	**************************************************/	
	public void push (t item){
		stackData.addFirst(item);
	}
	
	
	/**************************************************
	Method Name: pop
	Input to the method: none
	Output(Return value): t the next element
	Brief description of the task: removes the first element on the stack
	Throws: EMptyStackException if the stack is empty  
	Author: John Lawniczak
	**************************************************/
	public t pop () throws EmptyStackException{
		if(stackData.size()==0){
			throw new EmptyStackException();
		}
		return stackData.removeFirst();
	}
	
	
	/**************************************************
	Method Name: peek
	Input to the method: none
	Output(Return value): t the next element
	Brief description of the task: returns the first element on the stack
	Throws: EMptyStackException if the stack is empty  
	Author: John Lawniczak
	**************************************************/
	public t peek() throws EmptyStackException{
		if(stackData.size()==0){
			throw new EmptyStackException();
		}
		return stackData.getFirst();
	}
	/**************************************************
	Method Name: empty
	Input to the method: none
	Output(Return value): boolean true if the stack is empty
	Brief description of the task: tells you if the stack is empty or not
	Author: John Lawniczak
	**************************************************/
	public boolean empty(){
		if(stackData.size()==0){
			return true;
		}
		return false;
	}
	
	/**************************************************
	Method Name: size
	Input to the method: none
	Output(Return value): int the size of the stack
	Brief description of the task: returns the number of elements in the stack
	Author: John Lawniczak
	**************************************************/	
	public int size(){
		return stackData.size();
	}

	/**************************************************
	Method Name: toString
	Input to the method: none
	Output(Return value): String: all the elements in the stack
	Brief description of the task: returns the string that represents all the elements in the stack
	Author: John Lawniczak
	**************************************************/
	public String toString(){
		return stackData.toString();
	}
}
